package _18_剑指OfferII;

import java.util.ArrayList;
import java.util.List;

public class _110_剑指OfferII所有路径 {

    private List<List<Integer>> results = new ArrayList<>();

    // 深度求解路径
    public List<List<Integer>> allPathsSourceTarget(int[][] graph) {

        List<Integer> list = new ArrayList<>();
        list.add(0);
        dfs(graph, 0, list);

        return results;
    }

    private void dfs(int[][] graph, int index, List<Integer> list) {
        if (index == graph.length - 1) {
            results.add(new ArrayList<>(list));
            return;
        }

        int[] cur = graph[index];
        for (int next : cur) {
            list.add(next);
            dfs(graph, next, list);
            list.remove(list.size() - 1);
        }
    }
}


